﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using CE.iPhone.PList;
using System.IO;
namespace cczEdit
{
    
    public partial class Form1 : Form
    {
        private FolderBrowserDialog folderBrowserDialog;
        private UCHeroData ucHeroData;
        private UCItemData ucItemData;
        private UCMagicData ucMagicData;
        private UCTeamData ucTeamData;
        private UCTerrainData ucTerrainData;
        private UCShopData ucShopData;
        public UCDrama ucDrama;
        private Control currentControl;
        private UCUnitAnimSetting ucUnitAnimSetting;
        public static String cczDirector;
        public Form1()
        {
            Constant.init();
            currentControl = null;
            InitializeComponent();
            数据类型ToolStripMenuItem.Enabled = false;
            剧本ToolStripMenuItem.Enabled = false;
        }

        private void openFile(object sender, EventArgs e)
        {

            folderBrowserDialog = new FolderBrowserDialog();
            folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
            if (folderBrowserDialog.ShowDialog(this)==DialogResult.OK)
            {
                cczDirector = folderBrowserDialog.SelectedPath;
                数据类型ToolStripMenuItem.Enabled = true;
                剧本ToolStripMenuItem.Enabled = true;
            }

            Console.Write(cczDirector);
        }



        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl == null)
                return;
            if (this.ucHeroData == currentControl)
                this.ucHeroData.SaveAllData();
            else if (this.ucItemData == currentControl)
                this.ucItemData.SaveAllData();
            else if (this.ucMagicData == currentControl)
                this.ucMagicData.SaveAllData();
            else if (this.ucTeamData == currentControl)
                this.ucTeamData.SaveAllData();
            else if (this.ucTerrainData == currentControl)
                this.ucTerrainData.SaveAllData();
            else if(this.ucShopData==currentControl)
                ucShopData.SaveAllData();
        }

        private void 武将资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);

            this.ucHeroData = new UCHeroData(cczDirector);
            this.ucHeroData.Location = new System.Drawing.Point(0, 28);
            this.ucHeroData.Name = "ucHeroData";
            this.ucHeroData.Size = new System.Drawing.Size(703, 429);
            this.ucHeroData.TabIndex = 1;
            this.Controls.Add(ucHeroData);
            currentControl = ucHeroData;
        }

        private void 道具资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucItemData = new UCItemData(cczDirector);
            this.ucItemData.Location = new System.Drawing.Point(0, 28);
            this.ucItemData.Name = "ucItemData";
            this.ucItemData.Size = new System.Drawing.Size(703, 429);
            this.ucItemData.TabIndex = 1;
            this.Controls.Add(ucItemData);
            currentControl = ucItemData;
        }

        private void 策略资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucMagicData = new UCMagicData(cczDirector);
            this.ucMagicData.Location = new System.Drawing.Point(0, 28);
            this.ucMagicData.Name = "ucMagicData";
            this.ucMagicData.Size = new System.Drawing.Size(703, 429);
            this.ucMagicData.TabIndex = 1;
            this.Controls.Add(ucMagicData);
            currentControl = ucMagicData;
        }

        private void 兵种资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucTeamData = new UCTeamData(cczDirector);
            this.ucTeamData.Location = new System.Drawing.Point(0, 28);
            this.ucTeamData.Name = "ucTeamData";
            this.ucTeamData.Size = new System.Drawing.Size(703, 429);
            this.ucTeamData.TabIndex = 1;
            this.Controls.Add(ucTeamData);
            currentControl = ucTeamData;
        }
        private void 地形资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucTerrainData = new UCTerrainData(cczDirector);
            this.ucTerrainData.Location = new System.Drawing.Point(0, 28);
            this.ucTerrainData.Name = "ucTerrainData";
            this.ucTerrainData.Size = new System.Drawing.Size(703, 429);
            this.ucTerrainData.TabIndex = 1;
            this.Controls.Add(ucTerrainData);
            currentControl = ucTerrainData;
        }
        private void 商店资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucShopData = new UCShopData();
            this.ucShopData.Location = new System.Drawing.Point(0, 28);
            this.ucShopData.Name = "ucShopData";
            this.ucShopData.Size = new System.Drawing.Size(703, 429);
            this.ucShopData.TabIndex = 1;
            this.Controls.Add(ucShopData);
            currentControl = ucShopData;
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {

        }

        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.ucHeroData != null)
            {
                this.ucHeroData.SaveAllData();
            }
            else if (this.ucItemData != null)
            {
                this.ucItemData.SaveAllData();

            }
            else if (this.ucMagicData != null)
                this.ucMagicData.SaveAllData();
            else if (this.ucTeamData != null)
                this.ucTeamData.SaveAllData();
            else if (this.ucTerrainData != null)
                this.ucTerrainData.SaveAllData();
        }

        private void 导出常量字典ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PListRoot root = new PListRoot();
            PListDict rootDic = new PListDict();
            root.Root = rootDic;
            Constant.OutputConstantDictionary(root);
            
            root.Save("ConstantDictionary.plist",PListFormat.Xml);

        }
        private void 剧本ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucDrama = new UCDrama();

            this.ucDrama.Location = new System.Drawing.Point(0, 28);
            this.ucDrama.Name = "ucDrama";
            this.ucDrama.Size = new System.Drawing.Size(703, 429);
            this.ucDrama.TabIndex = 1;
            this.Controls.Add(ucDrama);
            currentControl = ucDrama;
        }

        private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.ucDrama == null)
                return;
            ucDrama.copySelectedInstructDict();
        }

        private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.ucDrama == null)
                return;
            this.ucDrama.pasteSelectedInstuctDict();
        }

        private void STeamAnimToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentControl != null)
                this.Controls.Remove(currentControl);
            this.ucUnitAnimSetting = new UCUnitAnimSetting();

            this.ucUnitAnimSetting.Location = new System.Drawing.Point(0, 28);
            this.ucUnitAnimSetting.Name = "ucUniAnim";
            this.ucUnitAnimSetting.Size = new System.Drawing.Size(703, 429);
            this.ucUnitAnimSetting.TabIndex = 1;
            this.Controls.Add(ucUnitAnimSetting);
            currentControl = ucUnitAnimSetting;
        }


    }
}
